package cn.tedu.sp06;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import java.util.logging.SimpleFormatter;



//@EnableCircuitBreaker
//@SpringBootApplication
//@EnableDiscoveryClient

@SpringCloudApplication
public class Sp06RibbonApplication {

	public static void main(String[] args) {
		SpringApplication.run(Sp06RibbonApplication.class, args);
	}


	/**
	 * 可以放在启动类中,
	 * 或者也可以放在自定义的自动配置类中
	 * */
	@Bean
	@LoadBalanced //ribbon的注解,对RestTemplate进行了增强,增加负载均衡的功能
	public RestTemplate restTemplate(){

		SimpleClientHttpRequestFactory f=new SimpleClientHttpRequestFactory();
		f.setConnectTimeout(1000);//连接的超时
		f.setReadTimeout(1000);//等待响应的超时

		//RestTemplate 中默认的 Factory 实例中，两个超时属性默认是 -1，
		//未启用超时，也不会触发重试

		return new RestTemplate(f);


	}




}

